package cn.sdormitory.controller.smartdor;

import cn.sdormitory.basedata.service.BClassService;
import cn.sdormitory.basedata.vo.BStudentLeaveCountVo;
import cn.sdormitory.common.api.CommonResult;
import cn.sdormitory.common.utils.DateTimeUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@Api(tags = "Smartdor-sdcount=> 请假统计")
@RequestMapping("/smartdor/sdcount")
public class SdCountController {
    @Autowired
   private BClassService bClassService;
   private BStudentLeaveCountVo bStudentLeaveCountVo;
    @ApiOperation("count => 查询请假次数信息")
    @PreAuthorize("@ss.hasPermi('smartdor:sdcount:count')")
    @GetMapping(value = "/count")
   public CommonResult<List<BStudentLeaveCountVo>>getStudentLeaveCount(@RequestParam Map<String, Object> params){

       String startDate=(String)params.get("startDate");
       String endDate=(String)params.get("endDate");
       if(startDate==null || startDate==""){
           Map<String,String> map= DateTimeUtils.getWeekDate();
           startDate=map.get("mondayDate");
           endDate=map.get("sundayDate");
       }
       String className=(String) params.get("classname");
       int classId=0;
       if(null!=className&&!"".equals(className)){
          String classId2= bClassService.getClassIdByClassName(className);
          if(null!=classId2&&!"".equals(classId2)){
              classId=Integer.parseInt(classId2);
          }
       }
       int index=Integer.parseInt((String) params.get("pageIndex"));
       int size=Integer.parseInt((String) params.get("size"));
        int total=Integer.parseInt(bClassService.getClassTotalCount(classId,startDate,endDate));
       if(index<=0){
           index=1;
       }
       List<BStudentLeaveCountVo> list=bClassService.countByClassIdWithDate(classId,startDate,endDate,index,size);
       for(BStudentLeaveCountVo bVo:list){
           bVo.setTotal(total);
       }
       return CommonResult.success(list);
   }
}
